Type.registerNamespace("Insp");
Type.registerNamespace("Insp.UI");

Insp.UI.ClientHoro = function(element)
{    
    Insp.UI.ClientHoro.initializeBase(this,[element]);
    this._title = "";
    this._energy = true;
    this._showenergy = true;
    this._lite = false;
    this._sign="";
    this._startDate = "";
    this._startDate = "" ;
    this._endDate = "";
    this._presentdate="";
    this._copyrightyear = "";
    this._tabselected = "horo";
    this._todaysHoroscopeDescription = "";
    this._todaysDate = "";
    this._todaysDisplayDate = "";
    this._todaysHasPrevDay = false;
    this._todaysHasNextDay = false;
    this._horoimg = "";
    this._selecteddate="";
    this._selectedmonth = "";
    this._resultarray = null;//new Array();
    this.month_names = new Array("","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");    
    this._horosign="";
    this._callbackDelegate = null;        
    this._callbackfailureDelegate = null;
    this._callbacksunshineDelegate = null;
    this._callbacksunshineFailureDelegate = null;
    
    this._leftnavigationDelegate = null;
    this._rightnavigationDelegate = null;
    
    this._horoClickdelegate = null;
    this._sunshineClickdelegate = null;
    
    
    this._components = [];    
}

Insp.UI.ClientHoro.prototype = {

    
    get_title: function(){ return this._title;},
    set_title: function(value){ this._title = value;this.raisePropertyChanged('title');},
    
    get_lite: function(){ return this._lite;},
    set_lite: function(value){ this._lite = value;this.raisePropertyChanged('lite');},

    get_energy: function(){return this._energy;},
    set_energy: function(value){this._energy = value;this.raisePropertyChanged('energy');},
   
    get_horoimg: function(){return this._horoimg;},
    set_horoimg: function(value){this._horoimg = value;this.raisePropertyChanged('horoimg');}, 
        
    get_showenergy: function(){return this._showenergy;},
    set_showenergy: function(value){this._showenergy = value;this.raisePropertyChanged('showenergy');},
    
    get_sign: function(){return this._sign;},
    set_sign: function(value){this._sign = value;this.raisePropertyChanged('sign');},
    
    get_startDate: function(){return this._startDate;},
    set_startDate: function(value){this._startDate = value;this.raisePropertyChanged('startDate');},
    
    get_endDate: function(){return this._endDate;},
    set_endDate: function(value){this._endDate = value;this.raisePropertyChanged('endDate');},
        
    get_presentdate: function(){return this._presentdate;},
    set_presentdate: function(value){this._presentdate = value;this.raisePropertyChanged('presentdate');},  
    
    
    //client horoscope related functions
    parseDate: function (date)
    {
        var daysplitarray = date.split("/");
        return parseInt(daysplitarray[1]);
    }, 
    
    parseMonth : function (date)
    {
        var daysplitarray = date.split("/");
        return this.month_names[parseInt(daysplitarray[0])].toString();
    },
    
    parseYear : function (date)
    {
        var daysplitarray = date.split("/");
        return daysplitarray[2];
    },
    
    formatDate: function(date)
    {
        var dt = new Date(date);
        dt = dt.format(strDateFormat);
        return strReading +" "+ dt;

    },
    populateDailyHoroscope : function ()
    {
        
        var boolElse = true; 
        var noFeed = true;
        for(var i=0; i< this._resultarray.length ; i++)
        {
            if(this._resultarray[i].date == this._presentdate)
            {
                noFeed = false;
                //Parse today's date, previous date and next date
                var tdate = this.parseDate(this._resultarray[i].date);
                var tmonth = this.parseMonth(this._resultarray[i].date);
                var tyear = this.parseYear(this._resultarray[i].date);
                
               
                if(this._resultarray[i].hasPrevDay && this._resultarray[i].hasNextDay && i < this._resultarray.length - 1 && i > 0)
                {
                    var previousdate = this.parseMonth(this._resultarray[i - 1].date) + " " + this.parseDate(this._resultarray[i - 1].date) + ",  " + this.parseYear(this._resultarray[i - 1 ].date);
                    var presentdate = this._resultarray[i].displayDate;
                    var nextdate = this.parseMonth(this._resultarray[i + 1].date) + " " + this.parseDate(this._resultarray[i + 1].date) + ",  " + this.parseYear(this._resultarray[i + 1].date);
                    //var temp = $get('horozeropaddingid', this.get_element());
                    //var test = temp;
                    $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'><div class='horoheader'><span style='font-family:Arial;cursor:pointer' class='horoNavBtn' id='imgBtn_Previous' name='imgBtn_Previous'>&#9668;</span><span class='pagination'>" + presentdate + "</span><span style='font-family:Arial;cursor:pointer' class='horoNavBtn' id='imgBtn_Next' name='imgBtn_Next'>&#9658;</span></div></div>";
                    this.removeLeftNavigationHandler();
                    this.removeRightNavigationHandler();
                    this.addLeftNavigationHandler();
                    this.addRightNavigationHandler();
                    boolElse = false;
                    //alert(1);
                }
                if(this._resultarray[i].hasPrevDay && !this._resultarray[i].hasNextDay && i > 0)
                {
                    //write code for only left image    
                    var previousdate = this.parseMonth(this._resultarray[i - 1].date) + " " + this.parseDate(this._resultarray[i - 1].date) + ",  " + this.parseYear(this._resultarray[i - 1 ].date);
                    var presentdate = this._resultarray[i].displayDate;
                    $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'><div class='horoheader'><span style='font-family:Arial;cursor:pointer' class='horoNavBtn' id='imgBtn_Previous' name='imgBtn_Previous'>&#9668;</span><span class='pagination'>" + presentdate + "</span></div></div>";
                    //this.removeLeftNavigationHandler();
                    //this.addLeftNavigationHandler();
                    
                    boolElse = false;
                    this.removeLeftNavigationHandler();
                    this.removeRightNavigationHandler();
                    this.addLeftNavigationHandler();
                    this.addRightNavigationHandler();
                    
                    //alert(2);

                }
                if(!this._resultarray[i].hasPrevDay && this._resultarray[i].hasNextDay && i < this._resultarray.length - 1)
                {
                    //write code for right image
                    var presentdate = this._resultarray[i].displayDate;
                    var nextdate = this.parseMonth(this._resultarray[i + 1].date) + " " + this.parseDate(this._resultarray[i + 1].date) + ",  " + this.parseYear(this._resultarray[i + 1].date);
                    $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'><div class='horoheader'><span class='pagination'>" + presentdate + "</span><span style='font-family:Arial;cursor:pointer' class='horoNavBtn' id='imgBtn_Next' name='imgBtn_Next'>&#9658;</span></div></div>";
                    //this.removeRightNavigationHandler();
                    //this.addRightNavigationHandler();
                    boolElse = false;
                    
                    this.removeLeftNavigationHandler();
                    this.removeRightNavigationHandler();
                    this.addLeftNavigationHandler();
                    this.addRightNavigationHandler();
                    
                    //alert(3);
                }
                if(!this._resultarray[i].hasPrevDay && !this._resultarray[i].hasNextDay)
                {
                    //hide both images
                    var presentdate = this._resultarray[i].displayDate;
                    $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'><div class='horoheader'><span class='pagination'>" + presentdate + "</span></div></div>";
                    //alert(4);
                    boolElse = false;
                } 
                
                if(boolElse)
                {
                    if(i == 0)
                    {
                        var presentdate = this._resultarray[i].displayDate;
                        var nextdate = this.parseMonth(this._resultarray[i + 1].date) + " " + this.parseDate(this._resultarray[i + 1].date) + ",  " + this.parseYear(this._resultarray[i + 1].date);
                        $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'><div class='horoheader'><span class='pagination'>" + presentdate + "</span><span style='font-family:Arial;cursor:pointer' class='horoNavBtn' id='imgBtn_Next' name='imgBtn_Next'>&#9658;</span></div></div>";   
                    }
                    if(i == this._resultarray.length - 1)
                    {   
                        var previousdate = this.parseMonth(this._resultarray[i - 1].date) + " " + this.parseDate(this._resultarray[i - 1].date) + ",  " + this.parseYear(this._resultarray[i - 1 ].date);
                        var presentdate = this._resultarray[i].displayDate;
                        $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'><div class='horoheader'><span style='font-family:Arial;cursor:pointer' class='horoNavBtn' id='imgBtn_Previous' name='imgBtn_Previous'>&#9668;</span><span class='pagination'>" + presentdate + "</span></div></div>";
                    }
                    
                    this.removeLeftNavigationHandler();
                    this.removeRightNavigationHandler();
                    this.addLeftNavigationHandler();
                    this.addRightNavigationHandler();
                }
                this._todaysHoroscopeDescription =  this._resultarray[i].description;   
                this._todaysDisplayDate =  this._resultarray[i].displayDate;   
                this._todaysHasPrevDay = this._resultarray[i].hasPrevDay;
                this._todaysHasNextDay = this._resultarray[i].hasNextDay;
                $get('horoimgSignTdId', this.get_element()).innerHTML = "<div id='horoStoryBodyID' class='horoStoryBody'>"+ this._resultarray[i].description+ "</div>";
                
                if(this.get_showenergy() && this.get_energy() && this._resultarray[i].energyLevel.toString() != '0')
                {                    
                    $get('hororowEnergyLineid', this.get_element()).innerHTML = "<hr/>";
                    $get('horoEnergyHeadingId', this.get_element()).innerHTML = "<div><h2 class='horoenergyheading' style='color:Black;'>"+strClientHoroscope_EnergyLvl+"</h2></div>";
                    var energyimage = this._resultarray[i].energyLevel.toString() + ".gif";
                    $get('horoEnergySummaryId', this.get_element()).innerHTML = "<div id='horodivEnergySummary'><table cellspacing='0' cellspadding='0' border='0' border-collapse='collapse'> <tr> <td class='horoenergybody' colspan='2'><div style='line-height:17px;'>"+strClientHoroscope_Relationships+"<br/>"+strClientHoroscope_Personal+"<br/>"+strClientHoroscope_WorkFinance+"</div> </td><td class='horoenergyImg'><div style='vertical-align:top;'><img id='imgEnergy' style='border-width:0px;' alt='Energy Level' src=" + energyimage+ " /></div></td></tr></table></div>";
                    $get('horoEnergyBottomId', this.get_element()).innerHTML = "<div>&copy;<a target='_blank' href='http://www.astrology.com'>Astrology.com</a> &#8482;1996 &#8211; <span>"+this.parseYear(this._copyrightyear)+ "</span> ."+strClientHoroscope_copyright+"</div>";
                }
                
            }
                           
        }
        if(this._resultarray.length == 1)
        {
           noFeed = false;
           var presentdate = this._resultarray[0].displayDate;
           
           $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'><div class='horoheader'><span class='pagination'>" + presentdate + "</span></div></div>";
           
                this._todaysHoroscopeDescription =  this._resultarray[0].description;   
                this._todaysDisplayDate =  this._resultarray[0].displayDate;   
                this._todaysHasPrevDay = this._resultarray[0].hasPrevDay;
                this._todaysHasNextDay = this._resultarray[0].hasNextDay;
                $get('horoimgSignTdId', this.get_element()).innerHTML = "<div id='horoStoryBodyID' class='horoStoryBody'>"+ this._resultarray[0].description+ "</div>";
                
                if(this.get_showenergy() && this.get_energy() && this._resultarray[0].energyLevel.toString() != '0')
                {                    
                    $get('hororowEnergyLineid', this.get_element()).innerHTML = "<hr/>";
                    $get('horoEnergyHeadingId', this.get_element()).innerHTML = "<div><h2 class='horoenergyheading' style='color:Black;'>"+strClientHoroscope_EnergyLvl+"</h2></div>";
                    var energyimage = this._resultarray[0].energyLevel.toString() + ".gif";
                    $get('horoEnergySummaryId', this.get_element()).innerHTML = "<div id='horodivEnergySummary'><table cellspacing='0' cellspadding='0' border='0' border-collapse='collapse'> <tr> <td class='horoenergybody' colspan='2'><div style='line-height:17px;'>"+strClientHoroscope_Relationships+"<br/>"+strClientHoroscope_Personal+"<br/>"+strClientHoroscope_WorkFinance+"</div> </td><td class='horoenergyImg'><div style='vertical-align:top;'><img id='imgEnergy' style='border-width:0px;' alt='Energy Level' src=" + energyimage+ " /></div></td></tr></table></div>";
                    $get('horoEnergyBottomId', this.get_element()).innerHTML = "<div>&copy;<a target='_blank' href='http://www.astrology.com'>Astrology.com</a> &#8482;1996 &#8211; <span>"+this.parseYear(this._copyrightyear)+ "</span> ."+strClientHoroscope_copyright+"</div>";
                }
        }
        if(noFeed)
        {
            this.get_element().innerHTML = "<div id='horoscopeContainer' style='margin:0;padding:1em 0;text-align:center' class='feedErrorMessage'>"+strGenericError+"</div>";
            return;
        }

    },
    
    addLeftNavigationHandler : function()
    {
      try{
          
                this._leftnavigationDelegate  = Function.createDelegate(this, this.leftnavigationDelegateHandler);            
                $addHandler($get('imgBtn_Previous' ,this.get_element()),'click',this._leftnavigationDelegate);
      }catch(e)
      {
        //do nothing
      }
    },
    leftnavigationDelegateHandler : function()
    {        
        //debugger;
        var date = "";
        for (var i =0 ; i < this._resultarray.length ; i ++)
        {
            if(this._resultarray[i].date == this._presentdate && this._resultarray[i].hasPrevDay && i > 0)
            {   
                var x = i - 1;
                date = this._resultarray[x].date;
            }
        }
        this._presentdate = date;               
        this.populateDailyHoroscope();
    },
    
    addRightNavigationHandler : function()
    {
      try{
                this._rightnavigationDelegate  = Function.createDelegate(this, this.rightnavigationDelegateHandler);            
                $addHandler($get('imgBtn_Next' ,this.get_element()),'click',this._rightnavigationDelegate);
          
      }catch(e)
      {
        //do nothing
      }
    },
    
    rightnavigationDelegateHandler : function()
    {
        var temp = this._resultarray;
        var date = "";
        for (var i =0 ; i < this._resultarray.length ; i ++)
        {
            if(this._resultarray[i].date == this._presentdate && this._resultarray[i].hasNextDay && i < this._resultarray.length -1) 
            {
                var x = i + 1;
                date = this._resultarray[x].date;
            }
        }
        this._presentdate = date;
        this.populateDailyHoroscope();
    },
    
    removeLeftNavigationHandler : function()
    {
        try{
            $removeHandler($get('imgBtn_Previous',this.get_element()),'click',this._leftnavigationDelegate);
            if(this._leftnavigationDelegate) this._leftnavigationDelegate = null;
        }catch(e)
        {
            //do nothing
        }
    },
    
    removeRightNavigationHandler : function()
    {
        try{
            $removeHandler($get('imgBtn_Next',this.get_element()),'click',this._rightnavigationDelegate);
            if(this._rightnavigationDelegate) this._rightnavigationDelegate = null;
        }catch(e)
        {
            //do nothing
        }    
    },
        
    dispose: function()
    {
        if(this._callbackDelegate) delete this._callbackDelegate;
        //$removeHandler($get('featuredMoviesubmit',this.get_element()),'click',this._buttonClickDelegate);
        //if(this._buttonClickDelegate) delete this._buttonClickDelegate;
        
		Insp.UI.ClientHoro.callBaseMethod(this,'dispose');
    },
    initialize: function()
    {
        
          Insp.UI.ClientHoro.callBaseMethod(this,'initialize');
 
          this._copyrightyear=this.get_presentdate();
 
          this.get_element().innerHTML = "<div id='horoscopeContainer' class='ptHoroClient'> " + 
          "<table cellspacing='0' cellspadding='0' border='0' border-collapse='collapse' class='horoBody'> " + 
            "<tr> <td class='horotdImage' id='horotdimageId'> </td></tr>" +
            "<tr><td id='horopaddingtabRowId' class='horopaddingtabrow' ></td> </tr>"+
            "<tr><td id='horozeropaddingid' class='horozeropadding' ></td> </tr>"+            
            "<tr><td class='horoimgSignTd' id='horoimgSignTdId'> </td></tr>" + 
            "<tr  ><td class='hororowEnergyLine'id='hororowEnergyLineid'></td></tr>"+
            "<tr > <td class='horozeropadding' id='horoEnergyHeadingId'></td></tr>" + 
            "<tr ><td class='horozeropadding' id='horoEnergySummaryId'></td></tr>" + 
            "<tr ><td class='horoEnergyBottom' id='horoEnergyBottomId'></td></tr>" + 
            "</table> </div>";
        
        this.addCssClass("ptHoroClient");
        this.addCssClass("HoroLoading");
		if (this._callbackDelegate === null) {
            this._callbackDelegate = Function.createDelegate(this, this.callbackHandler);
        }
        
        if (this._callbackfailureDelegate === null) {
            this._callbackfailureDelegate = Function.createDelegate(this, this.callbackfailureHandler);
        }
        if(this.get_lite())
        {
            $get('horopaddingtabRowId',this.get_element()).style.display='none';
        }
    },
    updated: function()
    {
        
          var sign = this.get_sign();
          var signsplit =  sign.split("(");
          var signname = signsplit[0].trim();
          this._horosign = signname;
          
          
        Portal.LightHoroscopeSvc.getClientDailyBySign(this._horosign, this.get_startDate(), this.get_endDate(),this._callbackDelegate,this._callbackfailureDelegate);
        Insp.UI.ClientHoro.callBaseMethod(this,'updated');
    },
    callbackHandler: function(results)
    {  	
        //debugger;
        //alert(results.length)
        this._resultarray = results;
        var temp = this._resultarray;
        this.removeCssClass("HoroLoading");
        //this._movieresult = results[0];
        this._clearComponents();
        this._createComponents();
    },
         
    callbackfailureHandler : function(failureresult)
    {
        this.get_element().innerHTML = "<div id='horoscopeContainer' style='margin:0;padding:1em 0;text-align:center' class='feedErrorMessage'>"+strGenericError+"</div>";
    },
        
    _createComponents: function()
    {    
    
      var temp = this._resultarray;
      if(temp == "" || temp == null)
      {
        this.get_element().innerHTML = "<div id='horoscopeContainer' style='margin:0;padding:1em 0;text-align:center' class='feedErrorMessage'>"+strGenericError+"</div>";
        return;
      } 
        $get('horotdimageId', this.get_element()).innerHTML = "<div> <img id='horoimgsign' class='horoImgSign' src='"+this.get_module().get_akamaiUrlPrefix()+this._horoimg+".gif"+this.get_module().get_akamaiUrlSuffix()+"'><span id='horosignname' class='horolabel_signname'>" + this._horosign + "</span> </div>";
        //Write a code for selection criteria
        if(this._tabselected == "horo")
        {
            $get('horopaddingtabRowId', this.get_element()).innerHTML = "<div style='padding-left: 8px; margin-right: 8px;' class='tabbutton tabstyle'><DIV id='dailyHoroscopeId' class='tabbutton_on' style='white-space:nowrap;'><DIV class='tabbutton_left'></DIV><SPAN><a>"+strClientHoroscope_DailyHoroscope+"</a></SPAN><DIV class='tabbutton_right'></DIV></DIV><DIV id='sunshineProfileId' class='tabbutton_off' style='white-space:nowrap;'><DIV class='tabbutton_left'></DIV><SPAN><a>"+strClientHoroscope_SunShine+"</a></SPAN><DIV class='tabbutton_right'></DIV></DIV></div>";        
        //check for three condition has previous, has next and has both 
            this._todaysDate = this._presentdate;
            this.populateDailyHoroscope();
        }  
        else
        {
            //write code for else part
        }
      
      //Adding handler to both the divs
      if(this._horoClickdelegate  === null)  
      {
            this._horoClickdelegate  = Function.createDelegate(this, this.horoClickdelegateHandler);            
            $addHandler($get('dailyHoroscopeId' ,this.get_element()),'click',this._horoClickdelegate);
      }
      
      if(this._sunshineClickdelegate  === null)  
      {
            this._sunshineClickdelegate  = Function.createDelegate(this, this.sunshineClickdelegateHandler);            
            $addHandler($get('sunshineProfileId' ,this.get_element()),'click',this._sunshineClickdelegate);
      }
      
      if (this._callbacksunshineDelegate === null) {
            this._callbacksunshineDelegate = Function.createDelegate(this, this.callbacksunshineDelegateHandler);
        }
        
        if (this._callbacksunshinefailureDelegate === null) {
            this._callbacksunshinefailureDelegate = Function.createDelegate(this, this.callbacksunshineDelegatefailureHandler);
        }
      
    },
    
    horoClickdelegateHandler : function()
    {
        if(this._tabselected == "horo")
        {
            //do nothing
        }else
        {
            
            this.removeLeftNavigationHandler();
            this.removeRightNavigationHandler();
        
            this._tabselected = "horo";
            var previousdate = this.parseMonth(this._todaysDate) + " " + this.parseDate(this._todaysDate) + ",  " + this.parseYear(this._todaysDate);
            var presentdate = this._todaysDisplayDate;
            var nextdate = this.parseMonth(this._todaysDate) + " " + this.parseDate(this._todaysDate) + ",  " + this.parseYear(this._todaysDate);
            $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'><div class='horoheader'><span id='imgBtn_Previous' style='font-family:Arial;cursor:pointer' class='horoNavBtn' name='imgBtn_Previous'>&#9668;</span><span class='pagination'>" + presentdate + "</span><span id='imgBtn_Next' name='imgBtn_Next' style='font-family:Arial;cursor:pointer'>&#9658;</span></div></div>";   
            $get('horoimgSignTdId', this.get_element()).innerHTML = "<div id='horoStoryBodyID' class='horoStoryBody'>"+ this._todaysHoroscopeDescription + "</div>";
            
            $get('imgBtn_Next', this.get_element()).style.display = (!this._todaysHasNextDay)?"none":"";
            $get('imgBtn_Previous', this.get_element()).style.display = (!this._todaysHasPrevDay)?"none":"";
            
            $get('dailyHoroscopeId', this.get_element()).className = "tabbutton_on";//
            $get('sunshineProfileId', this.get_element()).className = "tabbutton_off";
            
            //this._presentdate = this._todaysDate;
            this.removeLeftNavigationHandler();
            this.removeRightNavigationHandler();
            this.addLeftNavigationHandler();
            this.addRightNavigationHandler();
            
        }        
    },
    
    sunshineClickdelegateHandler : function()
    {
        if(this._tabselected == "horo")
        {   
            //Call web service to get sunshine long text
            Portal.LightHoroscopeSvc.getClientSunShineProfile(this._horosign,this._callbacksunshineDelegate,this._callbacksunshineDelegate);
        }else
        {
            //do nothing
        }
    },
    
    callbacksunshineDelegateHandler : function(sunshineresults)
    {
        
        //this.removeLeftNavigationHandler();
        //this.removeRightNavigationHandler();
        
        this._tabselected = "sunshine";
        var catstr="";
        catstr = (sunshineresults.dateRange!= "")?catstr + " (" + sunshineresults.dateRange + ")" : catstr;
        $get('horozeropaddingid', this.get_element()).innerHTML = "<div class='horotdImage'> <span style='font-weight:bold'>" +this._horosign+catstr+"</span></div>";
        var sunshineLongText = sunshineresults.longText.trim();
        $get('horoimgSignTdId', this.get_element()).innerHTML = "<div id='horoStoryBodyID' class='horoStoryBody'>"+ sunshineLongText+ "</div>";
        
        $get('dailyHoroscopeId', this.get_element()).className = "tabbutton_off";
        $get('sunshineProfileId', this.get_element()).className = "tabbutton_on";
        
        //this.addLeftNavigationHandler();
        //this.addRightNavigationHandler();
    },
    callbacksunshineDelegatefailureHandler : function()
    {
        //error condition
    },
    
    _clearComponents: function()
    {
        for(var a in this._components)
        {
            delete this._components[a];
        }
    },
    
    addComponent:function(e)
    {
        if(Sys.Component.isInstanceOfType(e))
            this._components[e.get_id()] = e;
    },
    getComponents:function()
    { 
        var a=[];b= this._components;
        for(var c in b)
        {
            a[a.length] = b[c];
        }
        return a;
    },
    findComponent:function(id)
    {
        return this._components[id];
    },
    removeComponent:function(b)
    {
        var a = b.get_id();
        if(a){delete this._components[a];}
    }
}

Insp.UI.ClientHoro.registerClass('Insp.UI.ClientHoro',Insp.UI.ModuleContentCtl,Sys.IContainer);


//Edit part code
Insp.UI.ClientHoroscopeParmsEdit = function(element)
{
    Insp.UI.ClientHoroscopeParmsEdit.initializeBase(this,[element]);
    
    this._title = "";
    this._showenergy = true;
    this._energy = true;
    this._lite = true;        
    this._sign="";    
    this._moduleClientID = null;
    this._signList =null;
    
//    this._saveBtnAnimation = null;
    this.horoscope = new Array("",strClientHoroscope_HoroscopeAries,strClientHoroscope_HoroscopeTaurus,strClientHoroscope_HoroscopeGemini,strClientHoroscope_HoroscopeCancer,strClientHoroscope_HoroscopeLeo,strClientHoroscope_HoroscopeVirgo,strClientHoroscope_HoroscopeLibra,strClientHoroscope_HoroscopeScorpio,strClientHoroscope_HoroscopeSagittarius,strClientHoroscope_HoroscopeCapricorn,strClientHoroscope_HoroscopeAquarius,strClientHoroscope_HoroscopePisces);
    this.signdates = new Array("",strClientHoroscope_Aries,strClientHoroscope_Taurus,strClientHoroscope_Gemini,strClientHoroscope_Cancer,strClientHoroscope_Leo,strClientHoroscope_Virgo,strClientHoroscope_Libra,strClientHoroscope_Scorpio,strClientHoroscope_Sagittarius,strClientHoroscope_Capricorn,strClientHoroscope_Aquarius,strClientHoroscope_Pisces);
    this._signCallbackDelegate = null;
    this._saveClickDelegate = null;
    this._headlineOnlyClickDelegate = null;
    this._showDetailClickDelegate = null;
    this._cancelClickDelegate = null;
    this._saveCallbackSuccessDelegate = null;
    this._saveCallbackFailureDelegate = null;        
}

Insp.UI.ClientHoroscopeParmsEdit.prototype = {
    get_title: function(){ return this._title;},
    set_title: function(value){ this._title = value;this.raisePropertyChanged('title');},
    
    get_showenergy: function(){return this._showenergy;},
    set_showenergy: function(value){this._showenergy = value;this.raisePropertyChanged('showenergy');},
    
    get_energy: function(){return this._energy;},
    set_energy: function(value){this._energy = value;this.raisePropertyChanged('energy');},

    get_lite: function(){ return this._lite;},
    set_lite: function(value){ this._lite = value;this.raisePropertyChanged('lite');},
    
    get_sign: function(){return this._sign;},
    set_sign: function(value){this._sign = value;this.raisePropertyChanged('sign');},
    
    get_saveBtnID: function(){return this._saveBtnID;},
    set_saveBtnID: function(value){this._saveBtnID = value;this.raisePropertyChanged('saveBtnID');},

    get_cancelBtnID: function(){return this._cancelBtnID;},
    set_cancelBtnID: function(value){this._cancelBtnID = value;this.raisePropertyChanged('cancelBtnID');},

    get_updatePanelID: function(){return this._updatePanelID;},
    set_updatePanelID: function(value){this._updatePanelID = value;this.raisePropertyChanged('updatePanelID');},

    get_moduleClientID: function(){return this._moduleClientID;},
    set_moduleClientID: function(value){this._moduleClientID = value;this.raisePropertyChanged('moduleClientID');},
    
    
    
    dispose: function()
    {
        //dffa

    },
    initialize: function()
    {
        
        Insp.UI.ClientHoroscopeParmsEdit.callBaseMethod(this,'initialize');
        if(this.get_lite() || !this.get_showenergy())
        {
            $get("energyOptDiv",this.get_element()).style.display='none';
        }        
        if (this._signCallbackDelegate === null) {
            this._signCallbackDelegate = Function.createDelegate(this, this._signCallbackHandler);
        }
        
        if (this._cancelClickDelegate === null) {
            this._cancelClickDelegate = Function.createDelegate(this, this._cancelClickHandler);
        }
        $addHandler($get('BtnCancel',this.get_element()),'click',this._cancelClickDelegate);
        
        if (this._saveClickDelegate === null) {
            this._saveClickDelegate = Function.createDelegate(this, this._saveClickHandler);
        }
        $addHandler($get('BtnSave',this.get_element()),'click',this._saveClickDelegate);
        
        if (this._saveCallbackSuccessDelegate === null) {
            this._saveCallbackSuccessDelegate = Function.createDelegate(this, this._saveCallbackSuccessHandler);
        }
        
        if (this._saveCallbackFailureDelegate === null) {
            this._saveCallbackFailureDelegate = Function.createDelegate(this, this._saveCallbackFailureHandler);
        }
        
    },    
    updated: function()
    {
        Portal.LightHoroscopeSvc.getSigns(this._signCallbackDelegate);
        Insp.UI.ClientHoroscopeParmsEdit.callBaseMethod(this,'updated');
    },
    
    _cancelClickHandler: function(eventObj)
    {
        this.get_module().set_showEditPart(false);
        this._initValues();
    },
    
    _initValues : function()
    {
        $get("CheckboxShowTooltip",this.get_element()).checked = this.get_energy();
        $get("SelSign",this.get_element()).value = this.get_sign();
    },
    
    _signCallbackHandler : function(results)
    {
        if(results != null && results.length > 0)
        {
            this._signList = results;
            var oSC=$get("SelSign",this.get_element());
            for(var i=0;i<results.length;i++)
            {
                var oOPT = document.createElement('OPTION');;
                oOPT.value = results[i].signCode;
                var catstr = results[i].signName.replace(/_/g," ");
                catstr =(results[i].beginDate!= "" && results[i].endDate!= "" )?catstr + " (" + results[i].beginDate + " - " + results[i].endDate + ")" : catstr;
                catstr = (results[i].dateRange!= "")?catstr + " (" + results[i].dateRange + ")" : catstr;
                oOPT.innerHTML = catstr;
                oSC.appendChild(oOPT);
            }
        }
        $get("CheckboxShowTooltip",this.get_element()).checked = this.get_energy();
        $get("SelSign",this.get_element()).value = this.get_sign();
    },
    _saveClickHandler: function(eventObj)
    {
        var sign = $get("SelSign",this.get_element()).value;  
        var horoscopefor = $get("SelSign",this.get_element()).value;  
        
        if(this._signList != null)
        {
            for(var i =0;i<this._signList.length;i++ )
            {
                if(this._signList[i].signCode == sign)
                {
                    horoscopefor = this._signList[i].signName;
                    break;
                }
            }
        }
        var energy = $get("CheckboxShowTooltip",this.get_element()).checked;        
        
        $get('BtnSave',this.get_element()).disabled=true;
        Portal.LightHoroscopeSvc.saveConfig(sign,energy,horoscopefor,this.get_moduleClientID(),this._saveCallbackSuccessDelegate,this._saveCallbackFailureDelegate);
    },
     _saveCallbackSuccessHandler: function(result)
    {
        
        if(result == "success")
        {
            if(this.get_module())this.get_module().refreshModule();
            this.get_module().set_showEditPart(false);
        }
    },
    _saveCallbackFailureHandler: function()
    {
         alert("in failed");
         $get('BtnSave',this.get_element()).disabled=false;
        
    }
}

Insp.UI.ClientHoroscopeParmsEdit.registerClass('Insp.UI.ClientHoroscopeParmsEdit',Insp.UI.ModuleEditCtl);



if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

Type.registerNamespace("Insp");
Type.registerNamespace("Insp.UI");

Insp.UI.ClientLottery = function(element)
{
    Insp.UI.ClientLottery.initializeBase(this,[element]);
    this._regionId = "";
    this._drawCount = 0;
    this._gameIds = "";
    this._countryId = "USA";
    this._title = "";
    
    this.lotteryGames = null;
    this.showGameIds = null;
    this._bShowAllGames= false;
    
    this._callbackDelegate = null;
    this._pageChangedDelegate = null;
}

Insp.UI.ClientLottery.prototype = {
    get_regionId: function(){return this._regionId;},
    set_regionId: function(value){this._regionId = value;this.raisePropertyChanged('regionId');},
    
    get_drawCount: function(){return this._drawCount;},
    set_drawCount: function(value){this._drawCount = value;this.raisePropertyChanged('drawCount');},

    get_gameIds: function(){return this._gameIds;},
    set_gameIds: function(value){this._gameIds = value;this.showGameIds=this._gameIds.split('|');this._bShowAllGames = (value == "*")?true:false;this.raisePropertyChanged('gameIds');},

    get_countryId: function(){return this._countryId;},
    set_countryId: function(value){this._countryId = value;this.raisePropertyChanged('countryId');},

    get_title: function(){return this._title;},
    set_title: function(value){this._title = value;this.raisePropertyChanged('title');},
    
    dispose: function()
    {
        if(this._callbackDelegate) delete this._callbackDelegate;
		Insp.UI.ClientLottery.callBaseMethod(this,'dispose');
    },
    initialize: function()
    {
        Insp.UI.ClientLottery.callBaseMethod(this,'initialize');
		this.addCssClass("ptModLottery");
		this.addCssClass("NHLoading");
		
    	if (this._callbackDelegate === null) {
            this._callbackDelegate = Function.createDelegate(this, this.callbackHandler);
        }
    },
    updated: function()
    {
        this.get_module().set_moduleTitle(this.get_title());
        Portal.ClientLotterySvc.a(this.get_regionId(),this.get_drawCount(),this.get_countryId(),this._callbackDelegate);
        Insp.UI.ClientLottery.callBaseMethod(this,'updated');
    },
    callbackHandler: function(results)
    {
		this.removeCssClass("NHLoading");
        this.lotteryGames = results;
        this._createComponents();
    },
    _createComponents: function()
    {
        var ctDiv = $get("contentDiv",this.get_element());
        var errDiv = $get("errorDiv",this.get_element());
        var hdrDiv = $get("headerDiv",this.get_element());
        
        if(this.lotteryGames == null || this.lotteryGames.length == 0)
        {            
            ctDiv.style.display = "none";
            hdrDiv.style.display = "none";
            errDiv.innerHTML = strGenericError;
            errDiv.style.display="";
            errDiv.className="ptGenericError";
            
        }else
        {
        
            errDiv.style.display = "none";
            hdrDiv.style.display = "";
            if(this._bShowAllGames ==false && (this.showGameIds == null || this.showGameIds.length == 0 || (this.showGameIds.length == 1 && this.showGameIds[0] == "")) )
            {
                errDiv.innerHTML = strNoGameMsg;
                errDiv.style.display = "";
                ctDiv.style.display="none";
                hdrDiv.style.display = "none";
            }else{
                errDiv.style.display = "none";
                ctDiv.style.display="";
                for(var i=0;i<this.lotteryGames.length;i++)
                {
                    var gm = this.lotteryGames[i];
                    var bShowGame = false;
                    if(this._bShowAllGames)
                    {
                        bShowGame = true;
                    }else
                    {
                        for(var j=0;j<this.showGameIds.length;j++)
                        {
                            if(gm.gameId == this.showGameIds[j])
                            {
                                bShowGame = true;
                            }
                        }
                    }
                    if(bShowGame)this._displayGame(gm);
                }
            }
        }
    },
    _displayGame:function(gm)
    {
        var ctDiv = $get("contentDiv",this.get_element());
        
        var gDiv = document.createElement('div');
        ctDiv.appendChild(gDiv);
        gDiv.className = "LotteryGameCont";
        gDiv.innerHTML = "<div id='GameName' class='GameTitle'>"+gm.name+"</div>" +
            "<div id='NextGame'><span id='nextDate' class='GameDate'>" +
                gm.nextDrawDate +
                "</span><span id='nextJackpot' class='GameResults'>"+ strClientLottery_NextGame +" "+ ((gm.jackpot!="0")?"$"+parseInt(gm.jackpot).localeFormat('i'):"") +"</span></div>" +
            "<div id='ResultsDiv' style='width:100%'></div>";
        
        var rDiv = $get('ResultsDiv',gDiv);
        var htm = "";
        for(var i=0;i<gm.drawings.length;i++)
        {
            var dr=gm.drawings[i];
            var reg = new RegExp(",","ig");
            var res = dr.results.toString().replace(reg,", ");
            htm+="<div><span class='GameDate'>"+dr.drawingDate+"</span>"+
                    "<span class='GameResults'>"+res+
                    "</span><span class='GameBonus'>"+((dr.bonus)?"<span style='font-family:Arial'>&nbsp;&#187;</span>"+dr.bonus:"")+"</span></div>";
        }
        rDiv.innerHTML = htm;
    },
    _getDisplayDate:function(dt)
    {
        var d= new Date(dt);
        return d.format("MM/dd");
    }
}

Insp.UI.ClientLottery.registerClass('Insp.UI.ClientLottery',Insp.UI.ModuleContentCtl);

Insp.UI.ClientLotteryEdit = function(element)
{
    Insp.UI.ClientLotteryEdit.initializeBase(this,[element]);
    this._regionId = "";
    this._drawCount = 0;
    this._gameIds = "";
    this._countryId = "USA";
    
    this._bShowAllGames = false;
    this.showGameIds = null;
    //Delegates
    this._regionCallbackDelegate = null;
    this._gamesCallbackDelegate = null;
    this._regionChangedDelegate = null;
    this._cancelClickDelegate = null;
    this._saveClickDelegate = null;
    this._propChangedDelegate = null
    this._saveSuccessDelegate = null;
    this._saveFailureDelegate = null;
}

Insp.UI.ClientLotteryEdit.prototype = {
    get_regionId: function(){return this._regionId;},
    set_regionId: function(value){this._regionId = value;this.raisePropertyChanged('regionId');},
    
    get_drawCount: function(){return this._drawCount;},
    set_drawCount: function(value){this._drawCount = value;this.raisePropertyChanged('drawCount');},

    get_gameIds: function(){return this._gameIds;},
    set_gameIds: function(value){this._gameIds = value;this.showGameIds=this._gameIds.split('|');this._bShowAllGames = (value == "*")?true:false;this.raisePropertyChanged('gameIds');},
    
    get_countryId: function(){return this._countryId;},
    set_countryId: function(value){this._countryId = value;this.raisePropertyChanged('countryId');},
    
    dispose: function()
    {
        if(this._saveFailureDelegate) delete this._saveFailureDelegate;
        if(this._saveSuccessDelegate) delete this._saveSuccessDelegate;
        if(this._propChangedDelegate) delete this._propChangedDelegate;
        $removeHandler($get('BtnSave',this.get_element()),'click',this._saveClickDelegate);
        if(this._saveClickDelegate) delete this._saveClickDelegate;
        $removeHandler($get('BtnCancel',this.get_element()),'click',this._cancelClickDelegate);
        if(this._cancelClickDelegate) delete this._cancelClickDelegate;
        $removeHandler($get('SelState',this.get_element()),'change',this._regionChangedDelegate);
        if(this._regionChangedDelegate) delete this._regionChangedDelegate;
        if(this._gamesCallbackDelegate) delete this._gamesCallbackDelegate;
        if(this._regionCallbackDelegate) delete this._regionCallbackDelegate;
        Insp.UI.ClientLotteryEdit.callBaseMethod(this,'dispose');
    },
    initialize: function()
    {
        Insp.UI.ClientLotteryEdit.callBaseMethod(this,'initialize');
        this.get_element().parentNode.style.position = "relative";
        this._disableSaveButton(true);
        
        if (this._regionCallbackDelegate === null) {
            this._regionCallbackDelegate = Function.createDelegate(this, this._regionCallbackHandler);
        }
        if (this._gamesCallbackDelegate === null) {
            this._gamesCallbackDelegate = Function.createDelegate(this, this._gamesCallbackHandler);
        }
        if (this._regionChangedDelegate === null) {
            this._regionChangedDelegate = Function.createDelegate(this, this._regionChangedHandler);
        }
        $addHandler($get('SelState',this.get_element()),'change',this._regionChangedDelegate);
        if (this._cancelClickDelegate === null) {
            this._cancelClickDelegate = Function.createDelegate(this, this._cancelClickHandler);
        }
        $addHandler($get('BtnCancel',this.get_element()),'click',this._cancelClickDelegate);
        if (this._saveClickDelegate === null) {
            this._saveClickDelegate = Function.createDelegate(this, this._saveClickHandler);
        }
        $addHandler($get('BtnSave',this.get_element()),'click',this._saveClickDelegate);
        if (this._propChangedDelegate === null) {
            this._propChangedDelegate = Function.createDelegate(this, this._propChangedHandler);
        }
        if (this._saveSuccessDelegate === null) {
            this._saveSuccessDelegate = Function.createDelegate(this, this._saveSuccessHandler);
        }
        if (this._saveFailureDelegate === null) {
            this._saveFailureDelegate = Function.createDelegate(this, this._saveFailureHandler);
        }                                 
        var oHLP = $get('SelDrawings',this.get_element());
        for(var i =1;i<=5;i++)
        {
            var oOPT = document.createElement('OPTION');;
            oOPT.value = ""+i;
            oOPT.innerHTML = i;
            oHLP.appendChild(oOPT);
        }
        
        this.get_module().add_propertyChanged(this._propChangedDelegate);
        this._initValues();
        
    },
    _initValues: function()
    {
        $get("SelDrawings",this.get_element()).value = this.get_drawCount();
        $get("SelState",this.get_element()).value = this.get_regionId();
        this._updateGameSelection();
    },
    updated: function()
    {
        Portal.ClientLotterySvc.b(this.get_countryId() ,this._regionCallbackDelegate);
        Insp.UI.ClientLotteryEdit.callBaseMethod(this,'updated');
    },
    _regionCallbackHandler:function(regions)
    {
        this._populateRegions(regions);
        this._retrieveGames(this.get_regionId());
        
    },
    _retrieveGames:function(regId)
    {
        this._disableSaveButton(true);
        $get('GamesListDiv',this.get_element()).innerHTML = "";
        Portal.ClientLotterySvc.a(regId,0,this.get_countryId(),this._gamesCallbackDelegate);
    },
    _gamesCallbackHandler:function(games)
    {
        this._populateGames(games);
        this._disableSaveButton(false);
    },
    _populateRegions:function(regions)
    {
        var oST = $get('SelState',this.get_element());
        for(var i =0;i<regions.length;i++)
        {
            var oOPT = document.createElement('OPTION');;
            oOPT.value = regions[i].regionId;
            oOPT.innerHTML = regions[i].name;
            oST.appendChild(oOPT);
        }
        oST.value = this.get_regionId();
    },
    _populateGames:function(games)
    {
        oGL = $get('GamesListDiv',this.get_element());
        oGL.innerHTML = "";
        for(var i =0;i<games.length;i++)
        {
            var oCT = document.createElement('div');
            oCT.innerHTML = "<input id='"+games[i].gameId+"' checked='checked' type='checkbox'><label for='"+games[i].gameId+"'>"+games[i].name+"</label>";
            oGL.appendChild(oCT);
        }
        this._updateGameSelection();
    },
    _updateGameSelection:function()
    {
        if($get("SelState",this.get_element()).value == this.get_regionId())
        {
            d = $get('GamesListDiv',this.get_element());
            var ids = d.getElementsByTagName('input');
            for(var i=0;i<ids.length;i++){
                var bshow = false;
                if(this._bShowAllGames)
                    bshow = true;
                else{
                    for(var j=0;j<this.showGameIds.length;j++){
                        if(ids[i].id == this.showGameIds[j])
                        {bshow= true;break;}
                    }
                }
                if(!bshow)ids[i].checked = false;
                else ids[i].checked = true;
            }
        }
    },
    _regionChangedHandler:function(evt)
    {
        var currReg = $get("SelState",this.get_element()).value;
        this._retrieveGames(currReg);
    },
    _disableSaveButton:function(state)
    {
        $get("BtnSave",this.get_element()).disabled = state;
    },
    _cancelClickHandler: function(eventObj)
    {
        this.get_module().set_showEditPart(false);
    },
    _saveClickHandler:function(evt)
    {
        this._saveConfig();
    },
    _saveConfig:function()
    {
        var oST=$get("SelState",this.get_element());
        var regID = oST.value;
        var regName = oST.options[oST.selectedIndex].text;
        var gameIds = "";
        d = $get('GamesListDiv',this.get_element());
        var ids = d.getElementsByTagName('input');
        for(var i=0;i<ids.length;i++){
            if(ids[i].checked)
            {
                gameIds += (gameIds == "")?"":"|";
                gameIds += ids[i].id;
            }
        }
        var numDraws = 1;
        numDraws = $get("SelDrawings",this.get_element()).value;
        
        Portal.ClientLotterySvc.s(regID,regName,gameIds,numDraws,this.get_module().get_moduleID(),this._saveSuccessDelegate,this._saveFailureDelegate);
    },
    _propChangedHandler:function(sender,prop)
    {
        if(prop.get_propertyName() == 'showEditPart' && !this.get_module().get_showEditPart())
        {        
            this._initValues();
            this._retrieveGames(this.get_regionId());
        }
    },
    _saveSuccessHandler:function(result)
    {
        if(result == "success")
        {
            if(this.get_module())this.get_module().refreshModule();
        }
    },
    _saveFailureHandler:function(result)
    {
    }
}

Insp.UI.ClientLotteryEdit.registerClass('Insp.UI.ClientLotteryEdit',Insp.UI.ModuleEditCtl);

// Since this script is not loaded by System.Web.Handlers.ScriptResourceHandler
// invoke Sys.Application.notifyScriptLoaded to notify ScriptManager 
// that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

